In Variable§

See primary documentation in context for trait is dynamic.

multi trait_mod:<is>(Variable:D, :$dynamic)

Marks a variable as dynamic, that is, accessible from inner dynamic scopes without being in an inner lexical scope.

sub introspect() {
    say $CALLER::x;
}
{
    my $x is dynamic = 42;
    introspect();  # OUTPUT: «42␤»
}
{
    my $x = 41;    # not dynamic
    introspect();  # dies with an exception of X::Caller::NotDynamic
}

The is dynamic trait is a rather cumbersome way of creating and accessing dynamic variables. A much easier way is to use the * twigil:

sub introspect() {
    say $*x;
}
{
    my $*x = 42;
    introspect();  # OUTPUT: «42␤»
}
{
    my $x = 41;    # not dynamic
    introspect();  # dies with an exception of X::Dynamic::NotFound
}